<?php
/**
 * Created by PhpStorm.
 * User: 贡7
 * Date: 2017/12/1
 * Time: 下午1:28
 */

namespace app\admin\controller;
use think\Db;

class Adjunct extends Admin
{
    /**
     * 附件上传
     * @return mixed
     */
    public function index()
    {
        $map = ['status' => 0];
        $list = Db::name('adjunct')->where($map)->order('id desc')->paginate();
        $this->assign('list', $list);

        return $this->fetch();
    }

    /**
     * 附件的添加
     * @return mixed
     */
    public function add(){
        if(IS_POST){
            $_POST['create_time'] = time();
            $_POST['status'] = 0;
            unset($_POST['id']);
            $result = Db::name('adjunct')->insert($_POST);
            if ($result) {

                return $this->success("添加成功！");
            } else {

                return $this->error("添加失败");
            }
        };

        return  $this->fetch();
    }

    /**
     * 删除
     */
    public function moveToTrash() {
        $ids = input('ids/a');
        $result = Db::name('adjunct')->where('id', 'in', $ids)->update(['status' => -1]);

        if($result) {

            return $this->success('删除成功');

        } elseif(!$result) {

            return $this->error('删除失败');
        }
    }
}